const express = require('express');
const { auth } = require('../../middleware/auth');
const validate = require('../../middleware/validate');
const systemController = require('../../controllers/system.controller');
const tagController = require('../../controllers/tag.controller');
const roleController = require('../../controllers/role.controller');
const backupController = require('../../controllers/backup.controller');
const notificationController = require('../../controllers/notification.controller');
const categoryController = require('../../controllers/category.controller');

const router = express.Router();

// 系统设置路由
router
  .route('/system')
  .get(auth('manageSystem'), systemController.getSystemSettings)
  .put(auth('manageSystem'), systemController.updateSystemSettings);

// 分类管理路由
router
  .route('/categories')
  .get(categoryController.getCategories);

router
  .route('/categories/:categoryId')
  .get(categoryController.getCategory);

// 标签管理路由
router
  .route('/tags')
  .post(auth('manageContent'), tagController.createTag)
  .get(auth('manageContent'), tagController.getTags);

router
  .route('/tags/:tagId')
  .get(auth('manageContent'), tagController.getTag)
  .put(auth('manageContent'), tagController.updateTag)
  .delete(auth('manageContent'), tagController.deleteTag);

// 角色权限路由
router
  .route('/roles')
  .post(auth('manageSystem'), roleController.createRole)
  .get(auth('manageSystem'), roleController.getRoles);

router
  .route('/roles/:roleId')
  .get(auth('manageSystem'), roleController.getRole)
  .put(auth('manageSystem'), roleController.updateRole)
  .delete(auth('manageSystem'), roleController.deleteRole);

// 备份管理路由
router
  .route('/backup-settings')
  .get(auth('manageSystem'), backupController.getBackupSettings)
  .put(auth('manageSystem'), backupController.updateBackupSettings);

router
  .route('/backups')
  .get(auth('manageSystem'), backupController.getBackups)
  .post(auth('manageSystem'), backupController.createBackup);

router
  .route('/backups/:backupId')
  .delete(auth('manageSystem'), backupController.deleteBackup);

router
  .route('/backups/:backupId/restore')
  .post(auth('manageSystem'), backupController.restoreBackup);

router
  .route('/backups/:backupId/download')
  .get(auth('manageSystem'), backupController.downloadBackup);

// 通知设置路由
router
  .route('/notification-settings')
  .get(auth('manageSystem'), notificationController.getNotificationSettings)
  .put(auth('manageSystem'), notificationController.updateNotificationSettings);

router
  .route('/notification-settings/test')
  .post(auth('manageSystem'), notificationController.testNotificationSend);

module.exports = router; 